#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

#define High 480
#define Width 640
#define PI 3.14159

int main()
{
	initgraph(Width,High);
	
	int center_x,center_y; // 中心坐标
	center_x = Width/2;
	center_y = High/2;
	
	int secondLength; // 秒针长度
	secondLength = Width/5;
	
	int minuteLength; // 分针长度
	minuteLength = Width/7;
	
	int hourLength; // 时针长度
	hourLength = Width/10;
	
	int secondEnd_x,secondEnd_y; // 秒针终点坐标
	int minuteEnd_x,minuteEnd_y; // 分针终点坐标
	int hourEnd_x,hourEnd_y; // 时针终点坐标
	
	float secondAngle = 0; // 秒针对应转动角度
	float minuteAngle = 0; // 分针对应转动角度
	float hourAngle = 0; // 时针对应转动角度
	
	SYSTEMTIME ti; // 定义变量存储系统时间
	
	BeginBatchDraw();
	// 画表盘
	circle(320, 240, 159);
	circle(320, 240, 160);
	circle(320, 240, 161);
	// 绘制刻度
	int x, y;
	for (int i=0; i<60; i++)
	{
		x = 320 + int(145 * sin(PI * 2 * i / 60));
		y = 240 + int(145 * cos(PI * 2 * i / 60));
		
		if (i % 15 == 0)
			bar(x - 5, y - 5, x + 5, y + 5);
		else if (i % 5 == 0)
			circle(x, y, 3);
		else
			putpixel(x, y, WHITE);
	}
	
	while(1)
	{
		GetLocalTime(&ti);
		secondAngle = ti.wSecond * 2*PI/60;
		minuteAngle = ti.wMinute * 2*PI/60;
		hourAngle = ti.wHour * 2*PI/12;
		
		secondEnd_x = center_x + secondLength * sin(secondAngle);
		secondEnd_y = center_y - secondLength * cos(secondAngle);
		minuteEnd_x = center_x + minuteLength * sin(minuteAngle);
		minuteEnd_y = center_y - minuteLength * cos(minuteAngle);
		hourEnd_x = center_x + hourLength * sin(hourAngle);
		hourEnd_y = center_y - hourLength * cos(hourAngle);
		
		// 画秒针
		setlinestyle(PS_SOLID,2);
		setcolor(RED);
		line(center_x,center_y,secondEnd_x,secondEnd_y);
		// 画分针
		setlinestyle(PS_SOLID,6);
		setcolor(LIGHTGRAY);
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);
		// 画时针
		setlinestyle(PS_SOLID,10);
		setcolor(WHITE);
		line(center_x,center_y,hourEnd_x,hourEnd_y);
		// 画LOGO
		setcolor(WHITE);
		outtextxy(280, 320, "Marshmellow");
		
		FlushBatchDraw();
		
		// 隐藏前针
		setcolor(BLACK);
		line(center_x,center_y,secondEnd_x,secondEnd_y);
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);
		line(center_x,center_y,hourEnd_x,hourEnd_y);
	}
	
	EndBatchDraw();
	getch();
	closegraph();
	return 0;
}